package io.xccit.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.xccit.pojo.User;
import io.xccit.pojo.dto.UserDTO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface IUserMapper extends BaseMapper<User> {


    /**
     * 查询所有
     * @return
     */
    @Select("select * from sys_user")
    List<User> findAll();

    /**
     * 添加用户
     * @param user
     * @return
     */
    @Insert("insert into sys_user(username,password,nickname,email,phone,address) values(#{username}," +
            "#{password},#{nickname},#{email},#{phone},#{address})")
    boolean save(User user);
    /**
     * 更新用户
     * @param user
     * @return
     */
    Integer update(User user);

    /**
     * 删除用户
     * @param id
     * @return
     */
    @Delete("delete from sys_user where id = #{id}")
    Integer delete(Integer id);
    //批量删除接口
    boolean batchDelete(List<Integer> ids);
    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Select("select * from sys_user limit #{pageNum},#{pageSize}")
    List<User> pageFind(Integer pageNum,Integer pageSize);
    /**
     * 查询条数
     * @return
     */
    @Select("select count(id) from sys_user")
    Integer total();
    /**
     *根据用户名模糊查询
     * @param username
     * @return
     */
    @Select("select * from sys_user where username like #{username}")
    List<User> findByUserName(String username);

    /**
     * 登录
     * @param userDTO
     * @return
     */
    @Select("select username,password from sys_user where username=#{userDTO.username} and password=#{userDTO.password}")
    UserDTO login(@Param("userDTO") UserDTO userDTO);
}
